<template>
  <div class="music-list-box">
    <div
      class="music-item"
      :class="{ currentItem: index === musicIndex }"
      v-for="(item, index) in musicLIst"
      :key="index"
      @click="emitSwitchMusic(item, index)"
    >
      <i
        class="music-item-icon iconfont icon-bofang"
        v-if="index === musicIndex"
      />
      <i v-else class="placeholder"></i>
      <span class="music-name">
        {{ item.name }}
      </span>
      <i
        class="add-music iconfont icon-jia"
        @click.stop="addFn(item, index)"
      ></i>
      <i
        class="delete-icon iconfont icon-shanchutianchong"
        @click.stop="delFn(item, index)"
      ></i>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    musicLIst: {
      type: Array,
      default: () => [],
    },
    musicIndex: {
      type: Number,
      default: 0,
    },
    lsMusicIndex: {
      type: Number,
      default: 0,
    },
  },
  methods: {
    emitSwitchMusic(item, index) {
      if (index === this.musicIndex) return;
      this.$emit("switchMusic", item);
    },
    addFn(item) {
      this.$emit("addmusic", item);
    },
    delFn(item, index) {
      this.$emit("upadte:lsMusicIndex", index);
      this.$emit("delmusic", item, index);
    },
  },
};
</script>

<style lang="scss" scoped>
.music-list-box {
  border-left: 1px solid #ccc;
}
.currentItem {
  background: rgba(150, 150, 150, 0.1);
}
.music-item {
  font-size: 12px;
  padding: 6px 10px;
  .music-item-icon {
    font-size: 14px;
    color: #c20c0c;
    margin-right: 5px;
  }
  .placeholder {
    width: 19px;
    display: inline-block;
  }
  &:hover {
    background: rgba(150, 150, 150, 0.1);
    .add-music,
    .delete-icon {
      display: inline-block;
    }
  }
  .music-name {
    display: inline-block;
    width: 120px;
  }
  .add-music {
    font-size: 14px;
    color: #333;
    display: none;
  }
  .delete-icon {
    font-size: 14px;
    display: none;
    float: right;
  }
  i {
    cursor: pointer;
  }
}
</style>